<template>
	<el-container>
		<el-aside width="35%">
			<el-container>
				<el-header>
					<div class="left-panel">
						<el-input v-model.trim="reqParams.key" clearable placeholder="关键字" />
					</div>
				</el-header>
				<el-main class="nopadding">
					<scTable
						ref="rtable"
						:api-obj="this.$API.procrouting.page"
						row-key="id"
						paginationLayout="prev, pager, next"
						highlightCurrentRow
						hideDo
						hideContextMenu
						@row-click="rowClick">
						<el-table-column label="#" type="index" align="center" width="20" />
						<el-table-column property="routingCode" label="路线编号" align="center" width="100" />
						<el-table-column property="routingName" label="路线名称" align="center" />
						<el-table-column property="lineCode" label="产线编号" align="center" width="100" />
					</scTable>
				</el-main>
			</el-container>
		</el-aside>

		<el-container>
			<el-header>
				<div class="left-panel">
					<el-button
						icon="el-icon-plus"
						type="primary"
						:disabled="(this.reqParams.routingId || 0) == 0"
						@click="open_dialog" />
				</div>
				<div class="right-panel">
					<div class="right-panel-search"></div>
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable
					ref="table"
					:api-obj="apiObj"
					:params="reqParams"
					row-key="id"
					:initData="false"
					hideDo
					hideContextMenu>
					<!-- 固定列-选择列 -->
					<el-table-column label="#" type="index" width="40" />
					<el-table-column property="product.itemCode" label="产品编号" align="center" width="140" />
					<el-table-column property="product.itemName" label="产品名称" align="center" width="160" />
					<el-table-column property="createTime" label="创建时间" align="center" />
					<el-table-column align="center" fixed="right" label="操作" width="140">
						<template #default="scope">
							<el-button text type="primary" size="small" @click="open_dialog(scope.row)">编辑</el-button>
							<el-divider direction="vertical" />
							<el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
								<template #reference>
									<el-button text type="primary" size="small">删除</el-button>
								</template>
							</el-popconfirm>
						</template>
					</el-table-column>
				</scTable>
			</el-main>

			<modify ref="modify" @complete="complete" />
		</el-container>
	</el-container>
</template>

<script>
import modify from "./modify";

export default {
	components: {
		modify,
	},
	data() {
		return {
			apiObj: this.$API.procroutingproduct.pagesbyroutingid,
			reqParams: {
				routingId: 0,
				routingCode: '',
				routingName: '',
			},
		};
	},
	mounted() {
	},
	methods: {
		complete() {
			this.$refs.table.refresh();
		},
		rowClick(row) {
			this.reqParams.routingId = row.id;
			this.reqParams.routingCode = row.routingCode;
			this.reqParams.routingName = row.routingName;
			this.$refs.table.reload(this.reqParams);
		},
		async table_del(row) {
			let resp = await this.$API.procroutingproduct.delete.delete([row.id]);
			if (resp.code == 200) {
				this.$refs.table.refresh();
				this.$message.success("删除成功");
			} else {
				this.$alert(resp.message, "提示", { type: "error" });
			}
		},
		open_dialog(row) {
			if (row.id) {
				this.$refs.modify.open(row, this.reqParams);
			} else {
				this.$refs.modify.open(null, this.reqParams);
			}
		},
	},
};
</script>
